package org.dochandler.esfinge.guardian.authorizer;

import org.dochandler.service.domain.Department;
import org.dochandler.service.domain.annotation.MissionWithinBudget;
import org.dochandler.service.domain.constants.Constants;
import org.dochandler.service.domain.mission.MissionRequest;
import org.esfinge.guardian.authorizer.Authorizer;
import org.esfinge.guardian.context.AuthorizationContext;

public class MissionWithinBudgetAuthorizer implements Authorizer<MissionWithinBudget> {

	@Override
	public Boolean authorize(AuthorizationContext context, MissionWithinBudget securityAnnotation) {
//		SituationOfState sos = context.getEnvironment().get( Constants.SITUATION_OF_STATE.val(), SituationOfState.class );
//		
//		if (sos == SituationOfState.WAR) return true;
		
		MissionRequest missionRequest = context.getResource().get( Constants.MISSION_REQUEST.val(), MissionRequest.class );
		Department department = context.getEnvironment().get( Constants.DEPARTMENT.val(), Department.class );
		
		Double missionBudget = missionRequest.getEstimatedCost();
		Double depBudget = department.getRemainingBudget();
		
		if (missionBudget <= depBudget ) {
			return true;
		}
		return false;
		
	}

}